﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Lamps_Studio.Models;

//using Lamps_Studio.ServicesLibrary; // Remote model services
                                    // please change to remote service if you want to use 

namespace Lamps_Studio.DataAccessLayer
{
    public class DataAccesHelper
    {
        public const string SECRET_KEY ="123456";

        #region Using local Datacontext

        LampStudioDataContextDataContext db = new LampStudioDataContextDataContext();

        public bool checkLogin(string USERNAME, string PASSWORD)
        {
            var existaccount = from m in db.LOGINs
                               where (m.USERNAME == USERNAME) && (m.PASSWORD == PASSWORD)
                               select m;
            if (existaccount.Any())
                return true;
            return false;

        }
        public string getCurrentDisplayName(string USERNAME)
        {
            var user = (from m in db.PROC_GetUserInfo(USERNAME) select m).FirstOrDefault();

            return user.DISPLAY_NAME;
        }
        public AuthenticationModel getLoginUserInfo(string USERNAME, string PASSWORD)
        {
            if (checkLogin(USERNAME, PASSWORD))
            {
                var user = (from m in db.PROC_GetUserInfo(USERNAME) select m).FirstOrDefault();
                AuthenticationModel model = new AuthenticationModel();
                model.USERNAME = user.USERNAME;
                model.PASSWORD = user.PASSWORD;
                model.ROLE_ID = user.ROLE_ID.ToString();
                model.IS_ACTIVE = user.IS_ACTIVE;
                return model;
            }
            else return null;
        }
        
        #endregion


        /* #region Using WCF services

        AuthenticationServiceClient services = new AuthenticationServiceClient();

        public bool checkLogin(string USERNAME, string PASSWORD)
        {
            if (services.checkLogin(USERNAME, PASSWORD,SECRET_KEY))
                return true;
            return false;

        }
        public string getCurrentDisplayName(string USERNAME)
        {
            return services.getCurrentUserName(USERNAME, SECRET_KEY);
        }
        public AuthenticationModel getAuthenticationInfo(string USERNAME, string PASSWORD)
        {
            return services.getAuthenticationInfo(USERNAME, PASSWORD, SECRET_KEY);
        }

        #endregion
        */
    }
}